﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using APB_PostSQL.Configuration;
using APB_PostSQL.Web;

namespace APB_PostSQL.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class APB_PostSQLDbContextFactory : IDesignTimeDbContextFactory<APB_PostSQLDbContext>
    {
        public APB_PostSQLDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<APB_PostSQLDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            APB_PostSQLDbContextConfigurer.Configure(builder, configuration.GetConnectionString(APB_PostSQLConsts.ConnectionStringName));

            return new APB_PostSQLDbContext(builder.Options);
        }
    }
}
